﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using exMath.Common;

namespace exMath.Calculus
{
    public class PolarFunction
    {
        private MathFunction _f;
        private ParametricEquation _p;
        
        public PolarFunction(MathFunction f)
        {
            _f = f;
            _p = new ParametricEquation(_polarx, _polary);
        }

        /// <summary>
        /// The original function that is of the form r=f(angle).
        /// </summary>
        public MathFunction Function
        {
            get
            {
                return _f;
            }
        }

        private double _polarx(double angle)
        {
            return _f(angle) * Math.Cos(angle);
        }

        private double _polary(double angle)
        {
            return _f(angle) * Math.Sin(angle);
        }

        /// <summary>
        /// Execute this function and 
        /// </summary>
        /// <param name="angle"></param>
        /// <returns></returns>
        public Point2D Execute(double angle)
        {
            return _p.Execute(angle);
        }

    }
}
